Skip to content

add fetch instructions to README #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2021
Merged

add fetch instructions to README #436

merged 2 commits into from
Jan 29, 2021

Conversation

llimllib
Copy link
Contributor

@llimllib llimllib commented Jan 29, 2021

It took me a little while to figure out, even though it's simple, so I thought it would be a good addition to the docs

It took me a little while to figure out, even though it's not simple, so I thought it would be a good addition to the docs
@llimllib
Copy link
Contributor Author

Something like this is what you'd prefer?

  const sqlPromise = initSqlJs({
    locateFile: file => `https://path/to/your/dist/folder/dist/${file}`
  });
  const dataPromise = fetch("/path/to/databse.sqlite").then(res => res.arrayBuffer());
  const [SQL, buf] = await Promise.all([sqlPromise, dataPromise]);
  const db = new SQL.Database(new Uint8Array(buf));

I hate those variable names, but dropping the Promise bit makes them super unclear to me. Suggestions, both on entirely what I'm doing and on preferable names, welcome

@llimllib
Copy link
Contributor Author

tbh I kind of prefer the non-promised version because the user is probably constructing the SQL object somewhere besides right where they're fetching the data? It's only there for reference really, and a user can make it more efficient if they want?

@llimllib
Copy link
Contributor Author

But of course it's your repo! So whatever makes sense to you wfm

@lovasoa
Copy link
Member

lovasoa commented Jan 29, 2021

  const sqlPromise = initSqlJs({
    locateFile: file => `https://path/to/your/dist/folder/dist/${file}`
  });
  const dataPromise = fetch("/path/to/databse.sqlite").then(res => res.arrayBuffer());
  const [SQL, buf] = await Promise.all([sqlPromise, dataPromise]);
  const db = new SQL.Database(new Uint8Array(buf));

This looks good to me. Just drop the extra indentation.

the user is probably constructing the SQL object somewhere besides right where they're fetching the data

Yes, they will probably have the creation of sqlPromise somewhere else. But the await for that promise should probably still be near the code that will use it, not near the code that instantiated it. I don't see a good reason to fetch the .wasm and the .sqlite sequentially instead of in parallel, even in the context of a larger application.

@llimllib
Copy link
Contributor Author

works for me, will update it

@lovasoa lovasoa merged commit 1220b7b into sql-js:master Jan 29, 2021
@llimllib
Copy link
Contributor Author

Thanks!

@llimllib llimllib deleted the add-fetch-instructions branch January 29, 2021 23:39
niurkacanals added a commit to niurkacanals/Dev-container-sql that referenced this pull request Sep 2, 2022
* add fetch instructions to README

It took me a little while to figure out, even though it's not simple, so I thought it would be a good addition to the docs

* use promise.all instead of sequential awaits

per discussion on sql-js/sql.js#436
brendasmith8 pushed a commit to brendasmith8/sql-database-server-develop that referenced this pull request Sep 22, 2022
* add fetch instructions to README

It took me a little while to figure out, even though it's not simple, so I thought it would be a good addition to the docs

* use promise.all instead of sequential awaits

per discussion on sql-js/sql.js#436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants